﻿<div class="container-fluid navbar-fixed-top top-bar">
    <div class="container-title">
        <div class="container-title-back" ng-click="back()"></div>
        <div class="container-title-main">住房公积金贷款额度计算器</div>
    </div>
</div>
<div class="clear50"></div>
<div class="fdjsq">
    <div class="container-fluid bg">
        <div class="row">
            <div class="clear20"></div>
            <div class="col-lg-6 col-md-6 col-xs-6 col-sm-6 border-right-w">
                <h3>最大贷款额度(元）</h3>
                <h4 class="loanLimit">
                    <img src="Content/img/h1.png" height="17" style=" vertical-align:top; margin-right:10px;">0.00
                </h4>
            </div>
            <div class="col-lg-6 col-md-6 col-xs-6 col-sm-6">
                <h3>最大贷款年限(年)</h3>
                <h4 class="loanYear">
                    <img src="Content/img/h2.png" height="17" style="vertical-align:top; margin-right:10px;">0.00
                </h4>
            </div>
            <div class="clear40"></div>
            <h3>&nbsp;&nbsp;&nbsp;说明：实际贷款额度以公积金中心测算为准。</h3>
        </div>
    </div>
</div>
<div class="container-fluid">
    <div class="putong">
        <div class="list-input">
            <input type="text" id="jishu" placeholder="请输入公积金基数">
        </div>
        <div class="list-input">
            <input type="text" id="rate" placeholder="请输入公积金缴存比例" style="width:90%">%
        </div>
        <div class="list-input">
            <input type="text" id="age" placeholder="请输入年龄">
        </div>
    </div>
    <br />
    <div>请选择性别</div>
    <div class="list-menu">
        <ul class="nav navbar-right">
            <li class="li-select">
                <select id="year" class="dropdown">
                    <option value="0" selected>男</option>
                    <option value="1">女</option>
                </select>
            </li>
        </ul>
    </div>
    <div class="clear40"></div>
    <button type="button" class="btn btn-default btn-block count">计算</button>
</div>
<div class="clear10"></div>
<script>
    $(".dropdown-menu li a").click(function () {
        $(this).parent().parent().parent().find("a").not(".dropdown-menu a").html($(this).html())
    })
</script>
<script>
    function houseFund(money, rate, age, sex) {
        var obj = new Object();
        obj.money = money;
        obj.age = age;
        obj.rate = rate;
        obj.sex = sex;
        obj.loanLimit = 0;
        obj.loanDate = 0;

        if (obj.money == "") {
            alert("请输入公积金数");
        } else if (isNaN(obj.money)) {
            alert("请输入正确的公积金数");
        } else if (obj.rate == "") {
            alert("请输入公积金缴存比例");
        } else if (obj.age == "") {
            alert("请输入年龄");
        } else if (isNaN(obj.age)) {
            alert("请输入正确的年龄");
        } else if (obj.sex == "女") {
            if (obj.age > 55) {
                alert("年龄不应大于55")
            } else if (obj.age < 0) {
                alert("年龄不应小于0")
            } else if (55 - obj.age > 20) {

                obj.loanDate = 20;
                if ((obj.money * obj.rate * 12 * 20) > 1000000) {
                    obj.loanLimit = 1000000;
                } else {
                    obj.loanLimit = obj.money * obj.rate * 12 * 20
                }
            } else {

                obj.loanDate = 20;
                if ((obj.money * obj.rate * 12 * 20) > 1000000)
                    obj.loanLimit = 1000000;
                else
                    obj.loanLimit = obj.money * obj.rate * 12 * (55 - obj.age);
            }
        } else {
            if (obj.age > 60) {
                alert("年龄不应大于60")
            } else if (obj.age < 0) {
                alert("年龄不应小于0")
            } else if (60 - obj.age > 20) {

                obj.loanDate = 20;
                if ((obj.money * obj.rate * 12 * 20) > 1000000)
                    obj.loanLimit = 1000000;
                else
                    obj.loanLimit = obj.money * obj.rate * 12 * 20;
            } else {
                obj.loanDate = 60 - obj.age;
                if ((obj.money * obj.rate * 12 * (60 - obj.age)) > 1000000) {
                    obj.loanLimit = 1000000;
                } else {
                    obj.loanLimit = obj.money * obj.rate * 12 * (60 - obj.age);
                }
            }
        }
        return obj;
    }
    $(".count").click(function () {
        var money = $("#jishu").val();
        var age = $("#age").val();
        var rate = $("#rate").val();
        var sex = $("#year option:selected").html();
        var fund = new houseFund(money, rate, age, sex);
        $(".loanLimit").html('<img src="Content/img/h1.png" height="17" style=" vertical-align:top; margin-right:10px;">' + fund.loanLimit);
        $(".loanYear").html('<img src="Content/img/h2.png" height="17" style="vertical-align:top; margin-right:10px;">' + fund.loanDate);
    })
</script>
